import router from '@/router'
import store from '@/store'

// 导航守卫
router.beforeEach(async(to, from, next) => {
  if (store.getters.token) {
    if (to.path === '/login') {
      next('/')
    } else {
      if (!store.getters.personal) {
        // console.log(1111)
        await store.dispatch('user/personal')
        // console.log(store.getters.personal)
      }
      next()
    }
  } else {
    const whileList = ['/login', '/404']
    if (whileList.indexOf(to.path) !== -1) {
      next()
    } else {
      next('/login')
    }
  }
})
